# -*- coding: utf-8 -*-
# 高级特性----排序算法
# sorted()也是一个高阶函数。用sorted()排序的关键在于实现一个映射函数
print(sorted([9,4,1,10,6,8,4,3,2,1]))

print(sorted([-9,4,-1,-10,6,8,4,3,-2,-1],key=abs))

print(sorted([-9,4,-1,-10,6,8,4,3,-2,-1],key=abs,reverse=True))

print(sorted(['f','s','a','b','x','c','w','q'],key = str.lower))

print(sorted(['f','s','a','b','x','c','w','q'],key = str.lower,reverse = True))


L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

def by_name(t):
    return t[0].lower()

def by_score(t):
    return t[1]

L2 = sorted(L, key=by_name)

print(L2)

L2 = sorted(L, key=by_score)
print(L2)